import {
	useAccountStore
} from '@/store';

export default {
	install(Vue) {
		let RouterTypes = ['navigateTo', 'redirectTo', 'switchTab', 'navigateBack', 'reLaunch'];
		RouterTypes.forEach(item => {
			uni.addInterceptor(item, {
				async invoke(e) { 
					const token = uni.getStorageSync('Authorization');
					const accountStore = useAccountStore();
					if (!token) {
						uni.showModal({
							title: '提示',
							content: '账号暂未登陆',
							showCancel: false,
							success: function(res) {
								uni.redirectTo({
									url: '/pages/login/index'
								})
							}
						});

					} else {
						await accountStore.getAccountInfo()
					}
					return e;
				},
				returnValue(e) {

				}
			});
		})
	}
}